package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.entity.GoodDetailListBean;
import com.zx.kitchen.index.common.entity.GoodsDayDetailsBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/21.
 */

public class GoodsDayDetailAdapter extends BaseAdapter {


    private List<GoodsDayDetailsBean> objects = new ArrayList<GoodsDayDetailsBean>();

    private Context context;
    private LayoutInflater layoutInflater;

    public GoodsDayDetailAdapter(Context context, List<GoodsDayDetailsBean> objects) {
        this.context = context;
        this.objects = objects;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public GoodsDayDetailsBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.adapter_goods_report_detail, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((GoodsDayDetailsBean) getItem(position), (ViewHolder) convertView.getTag(), position);
        return convertView;
    }

    private void initializeViews(GoodsDayDetailsBean object, ViewHolder holder, int position) {
        if (object.getDetail() ==null)return;
        holder.reportDate.setText("时间：   " + object.getDetail().get(position).getD());
        holder.reportUnit.setText("单位：   " + object.getDishes().getUnit());
        holder.reportPrice.setText("单价：   " + object.getDetail().get(position).getPrice() + "元");
        holder.reportNum.setText("数量：   " + object.getDetail().get(position).getNum());
        holder.reportTotal.setText("营业总额：   " + object.getDetail().get(position).getTotal() + "元");

    }

    protected class ViewHolder {

        private TextView reportDate;
        private TextView reportUnit;
        private TextView reportPrice;
        private TextView reportNum;
        private TextView reportTotal;

        public ViewHolder(View view) {

            reportDate = (TextView) view.findViewById(R.id.report_date);
            reportUnit = (TextView) view.findViewById(R.id.report_unit);
            reportPrice = (TextView) view.findViewById(R.id.report_price);
            reportNum = (TextView) view.findViewById(R.id.report_num);
            reportTotal = (TextView) view.findViewById(R.id.report_total);
        }
    }
}
